import config from "./config";
import { Environment } from "@/utils";
/**
 * host 域名管理
 */

enum ApiType {
  miniapi = "miniapi",
  upload = "upload",
  download = "download"
}

const host = {
  [ApiType.miniapi]: {
    [Environment.dev]: "https://abc.xxx.com",
    [Environment.prod]: "https://abc.xxx.com"
  },
  [ApiType.upload]: {
    [Environment.dev]: "https://abc.xxx.com",
    [Environment.prod]: "https://abc.xxx.com"
  },
  [ApiType.download]: {
    [Environment.dev]: "https://abc.xxx.com",
    [Environment.prod]: "https://abc.xxx.com"
  }
};

// 获取域名
function getHost(
  type: string = ApiType.miniapi,
  ENV: string = Environment.dev
) {
  return host[type][ENV];
}

export default new (class {
  // 上传toen
  private readonly _upload_token: string = `${getHost(
    ApiType.miniapi,
    config.ENV
  )}/xxx`;
  // 上传路径
  private readonly _upload: string = `${getHost(
    ApiType.miniapi,
    config.ENV
  )}/xxx`;
  // 授权路径
  private readonly _auth: string = `${getHost(
    ApiType.miniapi,
    config.ENV
  )}/xxx`;

  private readonly _segment: string = `${getHost(
    ApiType.miniapi,
    config.ENV
  )}/xxx`;
  private readonly _column: string = `${getHost(
    ApiType.miniapi,
    config.ENV
  )}/xxx`;

  public get base(): ApiBase {
    return {
      uploadToken: this._upload_token,
      upload: this._upload,
      auth: this._auth
    };
  }

  public get core(): ApiCore {
    return {
      segment: this._segment,
      column: this._column
    };
  }
})();

interface ApiBase {
  uploadToken: string;
  upload: string;
  auth: string;
}

interface ApiCore {
  segment: string;
  column: string;
}
